import numpy as np
from linearCostFunction import linear_cost_function
import scipy.optimize as opt

def train_linear_reg(X,Y,lmd):
	init_theta = np.ones(X.shape[1])

	def cost_func(t):
		return linear_cost_function(X,Y,t,lmd)[0]

	def grad_func(t):
		return linear_cost_function(X,Y,t,lmd)[1]

	theta,*unused = opt.fmin_cg(cost_func,init_theta,grad_func,maxiter=200,
								disp=False,full_output =True)

	return theta


